<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>zobrazovatko v 0.1.htm</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta name="generator" content="SynEdit HTML exporter" />
<style type="text/css">
<!--
body { color: #000000; background-color: #FFFFFF; }
.cpp1-assembler { color: #0000FF; }
.cpp1-character { color: #000000; }
.cpp1-comment { color: #3399FF; font-style: italic; }
.cpp1-float { color: #800080; }
.cpp1-hexadecimal { color: #800080; }
.cpp1-identifier { color: #000000; }
.cpp1-illegalchar { color: #000000; }
.cpp1-number { color: #800080; }
.cpp1-octal { color: #800080; }
.cpp1-preprocessor { color: #008000; }
.cpp1-reservedword { color: #000000; font-weight: bold; }
.cpp1-space { background-color: #FFFFFF; color: #000000; }
.cpp1-string { color: #FF0000; }
.cpp1-symbol { color: #000000; }
-->
</style>
</head>
<body>
<pre>
<code><span style="font: 10pt Courier New;">
<span class="cpp1-preprocessor">#include &lt;GL/openglut.h&gt;

#include &lt;stdarg.h&gt;
#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;

</span><span class="cpp1-reservedword">typedef</span><span class="cpp1-space"> </span><span class="cpp1-reservedword">struct</span><span class="cpp1-symbol">{
        </span><span class="cpp1-reservedword">int</span><span class="cpp1-space"> Z;
        </span><span class="cpp1-reservedword">float</span><span class="cpp1-space"> r[</span><span class="cpp1-number">3</span><span class="cpp1-symbol">];
} ATOMS;
</span><span class="cpp1-reservedword">typedef</span><span class="cpp1-space"> </span><span class="cpp1-reservedword">struct</span><span class="cpp1-symbol">{
        </span><span class="cpp1-reservedword">int</span><span class="cpp1-space"> X,Y;
        </span><span class="cpp1-reservedword">int</span><span class="cpp1-space"> type;
} BONDS;

</span><span class="cpp1-reservedword">float</span><span class="cpp1-space"> color_table[</span><span class="cpp1-number">128</span><span class="cpp1-symbol">][</span><span class="cpp1-number">3</span><span class="cpp1-symbol">];
</span><span class="cpp1-reservedword">char</span><span class="cpp1-space"> periodic_table[][</span><span class="cpp1-number">4</span><span class="cpp1-symbol">] = {
     </span><span class="cpp1-string">&quot;H&quot;</span><span class="cpp1-symbol">,                                                                                 </span><span class="cpp1-string">&quot;He&quot;</span><span class="cpp1-symbol">,
     </span><span class="cpp1-string">&quot;Li&quot;</span><span class="cpp1-symbol">,</span><span class="cpp1-string">&quot;Be&quot;</span><span class="cpp1-symbol">,                                                  </span><span class="cpp1-string">&quot;B&quot;</span><span class="cpp1-symbol">, </span><span class="cpp1-string">&quot;C&quot;</span><span class="cpp1-symbol">, </span><span class="cpp1-string">&quot;N&quot;</span><span class="cpp1-symbol">, </span><span class="cpp1-string">&quot;O&quot;</span><span class="cpp1-symbol">, </span><span class="cpp1-string">&quot;F&quot;</span><span class="cpp1-symbol">, </span><span class="cpp1-string">&quot;Ne&quot;</span><span class="cpp1-symbol">,
     </span><span class="cpp1-string">&quot;Na&quot;</span><span class="cpp1-symbol">,</span><span class="cpp1-string">&quot;Mg&quot;</span><span class="cpp1-symbol">,                                                  </span><span class="cpp1-string">&quot;Al&quot;</span><span class="cpp1-symbol">,</span><span class="cpp1-string">&quot;Si&quot;</span><span class="cpp1-symbol">,</span><span class="cpp1-string">&quot;P&quot;</span><span class="cpp1-symbol">, </span><span class="cpp1-string">&quot;S&quot;</span><span class="cpp1-symbol">, </span><span class="cpp1-string">&quot;Cl&quot;</span><span class="cpp1-symbol">,</span><span class="cpp1-string">&quot;Ar&quot;</span><span class="cpp1-symbol">,
     </span><span class="cpp1-string">&quot;K&quot;</span><span class="cpp1-symbol">, </span><span class="cpp1-string">&quot;Ca&quot;</span><span class="cpp1-symbol">,</span><span class="cpp1-string">&quot;Sc&quot;</span><span class="cpp1-symbol">,</span><span class="cpp1-string">&quot;Ti&quot;</span><span class="cpp1-symbol">,</span><span class="cpp1-string">&quot;V&quot;</span><span class="cpp1-symbol">, </span><span class="cpp1-string">&quot;Cr&quot;</span><span class="cpp1-symbol">,</span><span class="cpp1-string">&quot;Mn&quot;</span><span class="cpp1-symbol">,</span><span class="cpp1-string">&quot;Fe&quot;</span><span class="cpp1-symbol">,</span><span class="cpp1-string">&quot;Co&quot;</span><span class="cpp1-symbol">,</span><span class="cpp1-string">&quot;Ni&quot;</span><span class="cpp1-symbol">,</span><span class="cpp1-string">&quot;Cu&quot;</span><span class="cpp1-symbol">,</span><span class="cpp1-string">&quot;Zn&quot;</span><span class="cpp1-symbol">,</span><span class="cpp1-string">&quot;Ga&quot;</span><span class="cpp1-symbol">,</span><span class="cpp1-string">&quot;Ge&quot;</span><span class="cpp1-symbol">,</span><span class="cpp1-string">&quot;As&quot;</span><span class="cpp1-symbol">,</span><span class="cpp1-string">&quot;Se&quot;</span><span class="cpp1-symbol">,</span><span class="cpp1-string">&quot;Br&quot;</span><span class="cpp1-symbol">,</span><span class="cpp1-string">&quot;Kr&quot;</span><span class="cpp1-symbol">,
     </span><span class="cpp1-string">&quot;Rb&quot;</span><span class="cpp1-symbol">,</span><span class="cpp1-string">&quot;Sr&quot;</span><span class="cpp1-symbol">,</span><span class="cpp1-string">&quot;Y&quot;</span><span class="cpp1-symbol">, </span><span class="cpp1-string">&quot;Zr&quot;</span><span class="cpp1-symbol">,</span><span class="cpp1-string">&quot;Nb&quot;</span><span class="cpp1-symbol">,</span><span class="cpp1-string">&quot;Mo&quot;</span><span class="cpp1-symbol">,</span><span class="cpp1-string">&quot;Tc&quot;</span><span class="cpp1-symbol">,</span><span class="cpp1-string">&quot;Ru&quot;</span><span class="cpp1-symbol">,</span><span class="cpp1-string">&quot;Rh&quot;</span><span class="cpp1-symbol">,</span><span class="cpp1-string">&quot;Pd&quot;</span><span class="cpp1-symbol">,</span><span class="cpp1-string">&quot;Ag&quot;</span><span class="cpp1-symbol">,</span><span class="cpp1-string">&quot;Cd&quot;</span><span class="cpp1-symbol">,</span><span class="cpp1-string">&quot;In&quot;</span><span class="cpp1-symbol">,</span><span class="cpp1-string">&quot;Sn&quot;</span><span class="cpp1-symbol">,</span><span class="cpp1-string">&quot;Sb&quot;</span><span class="cpp1-symbol">,</span><span class="cpp1-string">&quot;Te&quot;</span><span class="cpp1-symbol">,</span><span class="cpp1-string">&quot;I&quot;</span><span class="cpp1-symbol">, </span><span class="cpp1-string">&quot;Xe&quot;</span><span class="cpp1-symbol">,
     </span><span class="cpp1-string">&quot;Cs&quot;</span><span class="cpp1-symbol">,</span><span class="cpp1-string">&quot;Ba&quot;</span><span class="cpp1-symbol">,</span><span class="cpp1-string">&quot;La&quot;</span><span class="cpp1-symbol">,
         </span><span class="cpp1-string">&quot;Ce&quot;</span><span class="cpp1-symbol">,</span><span class="cpp1-string">&quot;Pr&quot;</span><span class="cpp1-symbol">,</span><span class="cpp1-string">&quot;Nd&quot;</span><span class="cpp1-symbol">,</span><span class="cpp1-string">&quot;Pm&quot;</span><span class="cpp1-symbol">,</span><span class="cpp1-string">&quot;Sm&quot;</span><span class="cpp1-symbol">,</span><span class="cpp1-string">&quot;Eu&quot;</span><span class="cpp1-symbol">,</span><span class="cpp1-string">&quot;Gd&quot;</span><span class="cpp1-symbol">,</span><span class="cpp1-string">&quot;Tb&quot;</span><span class="cpp1-symbol">,</span><span class="cpp1-string">&quot;Dy&quot;</span><span class="cpp1-symbol">,</span><span class="cpp1-string">&quot;Ho&quot;</span><span class="cpp1-symbol">,</span><span class="cpp1-string">&quot;Er&quot;</span><span class="cpp1-symbol">,</span><span class="cpp1-string">&quot;Tm&quot;</span><span class="cpp1-symbol">,</span><span class="cpp1-string">&quot;Yb&quot;</span><span class="cpp1-symbol">,</span><span class="cpp1-string">&quot;Lu&quot;</span><span class="cpp1-symbol">,
                    </span><span class="cpp1-string">&quot;Hf&quot;</span><span class="cpp1-symbol">,</span><span class="cpp1-string">&quot;Ta&quot;</span><span class="cpp1-symbol">,</span><span class="cpp1-string">&quot;W&quot;</span><span class="cpp1-symbol">, </span><span class="cpp1-string">&quot;Re&quot;</span><span class="cpp1-symbol">,</span><span class="cpp1-string">&quot;Os&quot;</span><span class="cpp1-symbol">,</span><span class="cpp1-string">&quot;Ir&quot;</span><span class="cpp1-symbol">,</span><span class="cpp1-string">&quot;Pt&quot;</span><span class="cpp1-symbol">,</span><span class="cpp1-string">&quot;Au&quot;</span><span class="cpp1-symbol">,</span><span class="cpp1-string">&quot;Hg&quot;</span><span class="cpp1-symbol">,</span><span class="cpp1-string">&quot;Tl&quot;</span><span class="cpp1-symbol">,</span><span class="cpp1-string">&quot;Pb&quot;</span><span class="cpp1-symbol">,</span><span class="cpp1-string">&quot;Bi&quot;</span><span class="cpp1-symbol">,</span><span class="cpp1-string">&quot;Po&quot;</span><span class="cpp1-symbol">,</span><span class="cpp1-string">&quot;At&quot;</span><span class="cpp1-symbol">,</span><span class="cpp1-string">&quot;Rn&quot;</span><span class="cpp1-symbol">,
     </span><span class="cpp1-string">&quot;Fr&quot;</span><span class="cpp1-symbol">,</span><span class="cpp1-string">&quot;Ra&quot;</span><span class="cpp1-symbol">,</span><span class="cpp1-string">&quot;Ac&quot;</span><span class="cpp1-symbol">,
         </span><span class="cpp1-string">&quot;Tb&quot;</span><span class="cpp1-symbol">,</span><span class="cpp1-string">&quot;Pa&quot;</span><span class="cpp1-symbol">,</span><span class="cpp1-string">&quot;U&quot;</span><span class="cpp1-symbol">,</span><span class="cpp1-string">&quot;Np&quot;</span><span class="cpp1-symbol">,</span><span class="cpp1-string">&quot;Pu&quot;</span><span class="cpp1-symbol">,</span><span class="cpp1-string">&quot;Am&quot;</span><span class="cpp1-symbol">,</span><span class="cpp1-string">&quot;Cm&quot;</span><span class="cpp1-symbol">,</span><span class="cpp1-string">&quot;Bk&quot;</span><span class="cpp1-symbol">,</span><span class="cpp1-string">&quot;Cf&quot;</span><span class="cpp1-symbol">,</span><span class="cpp1-string">&quot;Es&quot;</span><span class="cpp1-symbol">,</span><span class="cpp1-string">&quot;Fm&quot;</span><span class="cpp1-symbol">,</span><span class="cpp1-string">&quot;Md&quot;</span><span class="cpp1-symbol">,</span><span class="cpp1-string">&quot;No&quot;</span><span class="cpp1-symbol">,</span><span class="cpp1-string">&quot;Lr&quot;</span><span class="cpp1-symbol">,
                    </span><span class="cpp1-string">&quot;Rf&quot;</span><span class="cpp1-symbol">,</span><span class="cpp1-string">&quot;Ha&quot;</span><span class="cpp1-symbol">};
</span><span class="cpp1-reservedword">int</span><span class="cpp1-space"> getZ(</span><span class="cpp1-reservedword">char</span><span class="cpp1-space"> *symbol){
    </span><span class="cpp1-reservedword">int</span><span class="cpp1-space"> i;
    </span><span class="cpp1-reservedword">for</span><span class="cpp1-symbol">(i=</span><span class="cpp1-number">0</span><span class="cpp1-symbol">;i&lt;</span><span class="cpp1-number">100</span><span class="cpp1-symbol">;i++)
      </span><span class="cpp1-reservedword">if</span><span class="cpp1-space"> (!stricmp(symbol,periodic_table[i])) </span><span class="cpp1-reservedword">return</span><span class="cpp1-space"> i+</span><span class="cpp1-number">1</span><span class="cpp1-symbol">;
    </span><span class="cpp1-reservedword">return</span><span class="cpp1-space"> </span><span class="cpp1-number">0</span><span class="cpp1-symbol">;
}

</span><span class="cpp1-reservedword">void</span><span class="cpp1-space"> load_color_table(</span><span class="cpp1-reservedword">void</span><span class="cpp1-symbol">){
     FILE *f = fopen(</span><span class="cpp1-string">&quot;barvy.txt&quot;</span><span class="cpp1-symbol">,</span><span class="cpp1-string">&quot;r&quot;</span><span class="cpp1-symbol">);
     </span><span class="cpp1-reservedword">char</span><span class="cpp1-space"> line[</span><span class="cpp1-number">512</span><span class="cpp1-symbol">];
     </span><span class="cpp1-reservedword">int</span><span class="cpp1-space"> i,j;
     </span><span class="cpp1-reservedword">float</span><span class="cpp1-space"> r,g,b;
     
     </span><span class="cpp1-reservedword">char</span><span class="cpp1-space"> tmp[</span><span class="cpp1-number">8</span><span class="cpp1-symbol">];
     
     </span><span class="cpp1-reservedword">for</span><span class="cpp1-symbol">(i=</span><span class="cpp1-number">0</span><span class="cpp1-symbol">;i&lt;</span><span class="cpp1-number">128</span><span class="cpp1-symbol">;i++) 
      </span><span class="cpp1-reservedword">for</span><span class="cpp1-symbol">(j=</span><span class="cpp1-number">0</span><span class="cpp1-symbol">;j&lt;</span><span class="cpp1-number">3</span><span class="cpp1-symbol">;j++) 
       color_table[i][j]=</span><span class="cpp1-float">0.5</span><span class="cpp1-symbol">;
       
     </span><span class="cpp1-reservedword">while</span><span class="cpp1-symbol">(!feof(f)){
       fgets(line,</span><span class="cpp1-number">512</span><span class="cpp1-symbol">,f);
       sscanf(line,</span><span class="cpp1-string">&quot;%s %f %f %f&quot;</span><span class="cpp1-symbol">,tmp,&amp;r,&amp;g,&amp;b);
       i = getZ(tmp);
       color_table[i][</span><span class="cpp1-number">0</span><span class="cpp1-symbol">]=r;
       color_table[i][</span><span class="cpp1-number">1</span><span class="cpp1-symbol">]=g;
       color_table[i][</span><span class="cpp1-number">2</span><span class="cpp1-symbol">]=b;        
       printf(</span><span class="cpp1-string">&quot;Barva %d %f %f %f\n&quot;</span><span class="cpp1-symbol">,i,r,g,b);             
     }     
     fclose(f);
}

</span><span class="cpp1-reservedword">void</span><span class="cpp1-space"> load_molfile(</span><span class="cpp1-reservedword">char</span><span class="cpp1-space"> *fn,</span><span class="cpp1-reservedword">int</span><span class="cpp1-space"> *nA,</span><span class="cpp1-reservedword">int</span><span class="cpp1-space"> *nB,ATOMS **A,BONDS **B,</span><span class="cpp1-reservedword">float</span><span class="cpp1-space"> *scale){
     FILE *f = fopen(fn,</span><span class="cpp1-string">&quot;r&quot;</span><span class="cpp1-symbol">);
     </span><span class="cpp1-reservedword">char</span><span class="cpp1-space"> line[</span><span class="cpp1-number">512</span><span class="cpp1-symbol">],tmp[</span><span class="cpp1-number">16</span><span class="cpp1-symbol">];
     ATOMS *Atmp;
     BONDS *Btmp;
     </span><span class="cpp1-reservedword">int</span><span class="cpp1-space"> i,j;
     </span><span class="cpp1-reservedword">float</span><span class="cpp1-space"> rmin[</span><span class="cpp1-number">3</span><span class="cpp1-symbol">]={</span><span class="cpp1-float">1e20</span><span class="cpp1-symbol">,</span><span class="cpp1-float">1e20</span><span class="cpp1-symbol">,</span><span class="cpp1-float">1e20</span><span class="cpp1-symbol">},rmax[</span><span class="cpp1-number">3</span><span class="cpp1-symbol">]={-</span><span class="cpp1-float">1e20</span><span class="cpp1-symbol">,-</span><span class="cpp1-float">1e20</span><span class="cpp1-symbol">,-</span><span class="cpp1-float">1e20</span><span class="cpp1-symbol">};

     </span><span class="cpp1-reservedword">for</span><span class="cpp1-symbol">(i=</span><span class="cpp1-number">0</span><span class="cpp1-symbol">;i&lt;</span><span class="cpp1-number">4</span><span class="cpp1-symbol">;i++)
       fgets(line,</span><span class="cpp1-number">512</span><span class="cpp1-symbol">,f);
 
     sscanf(line,</span><span class="cpp1-string">&quot;%3d%3d&quot;</span><span class="cpp1-symbol">,nA,nB);
 
     *A = (ATOMS *)malloc(*nA*</span><span class="cpp1-reservedword">sizeof</span><span class="cpp1-symbol">(ATOMS));       
     *B = (BONDS *)malloc(*nB*</span><span class="cpp1-reservedword">sizeof</span><span class="cpp1-symbol">(BONDS));       
     
     </span><span class="cpp1-reservedword">for</span><span class="cpp1-symbol">(i=</span><span class="cpp1-number">0</span><span class="cpp1-symbol">;i&lt;*nA;i++){
       fgets(line,</span><span class="cpp1-number">512</span><span class="cpp1-symbol">,f);
       Atmp = &amp;(*A)[i];
       sscanf(line,</span><span class="cpp1-string">&quot;%10f%10f%10f%s&quot;</span><span class="cpp1-symbol">,&amp;Atmp-&gt;r[</span><span class="cpp1-number">0</span><span class="cpp1-symbol">],&amp;Atmp-&gt;r[</span><span class="cpp1-number">1</span><span class="cpp1-symbol">],&amp;Atmp-&gt;r[</span><span class="cpp1-number">2</span><span class="cpp1-symbol">],tmp);
       Atmp-&gt;Z=getZ(tmp);
     }

     </span><span class="cpp1-reservedword">for</span><span class="cpp1-symbol">(i=</span><span class="cpp1-number">0</span><span class="cpp1-symbol">;i&lt;*nB;i++){
       fgets(line,</span><span class="cpp1-number">512</span><span class="cpp1-symbol">,f);
       Btmp = &amp;(*B)[i];
       sscanf(line,</span><span class="cpp1-string">&quot;%3d%3d%3d&quot;</span><span class="cpp1-symbol">,&amp;Btmp-&gt;X,&amp;Btmp-&gt;Y,&amp;Btmp-&gt;type);
       Btmp-&gt;X--;
       Btmp-&gt;Y--;
     }

     </span><span class="cpp1-reservedword">for</span><span class="cpp1-symbol">(i=</span><span class="cpp1-number">0</span><span class="cpp1-symbol">;i&lt;*nA;i++)</span><span class="cpp1-reservedword">for</span><span class="cpp1-symbol">(j=</span><span class="cpp1-number">0</span><span class="cpp1-symbol">;j&lt;</span><span class="cpp1-number">3</span><span class="cpp1-symbol">;j++){
            </span><span class="cpp1-reservedword">if</span><span class="cpp1-space"> ((*A)[i].r[j]&lt;rmin[j]) rmin[j]=(*A)[i].r[j];        
            </span><span class="cpp1-reservedword">if</span><span class="cpp1-space"> ((*A)[i].r[j]&gt;rmax[j]) rmax[j]=(*A)[i].r[j];        
     }
     
     </span><span class="cpp1-reservedword">for</span><span class="cpp1-symbol">(j=</span><span class="cpp1-number">0</span><span class="cpp1-symbol">,*scale=</span><span class="cpp1-number">0</span><span class="cpp1-symbol">;j&lt;</span><span class="cpp1-number">3</span><span class="cpp1-symbol">;j++)
       </span><span class="cpp1-reservedword">if</span><span class="cpp1-space"> (*scale&lt;rmax[j]-rmin[j]) *scale = rmax[j]-rmin[j];
     
     </span><span class="cpp1-reservedword">for</span><span class="cpp1-symbol">(i=</span><span class="cpp1-number">0</span><span class="cpp1-symbol">;i&lt;*nA;i++)</span><span class="cpp1-reservedword">for</span><span class="cpp1-symbol">(j=</span><span class="cpp1-number">0</span><span class="cpp1-symbol">;j&lt;</span><span class="cpp1-number">3</span><span class="cpp1-symbol">;j++)
            (*A)[i].r[j]=((*A)[i].r[j]-</span><span class="cpp1-float">0.5</span><span class="cpp1-symbol">*(rmax[j]+rmin[j]));        
     fclose(f);
}
</span><span class="cpp1-preprocessor">#define KONSTANTA 0.08
#define RADIUS 1.6

</span><span class="cpp1-reservedword">void</span><span class="cpp1-space"> cross_product(</span><span class="cpp1-reservedword">float</span><span class="cpp1-space"> *c, </span><span class="cpp1-reservedword">float</span><span class="cpp1-space"> *a, </span><span class="cpp1-reservedword">float</span><span class="cpp1-space"> *b){
     c[</span><span class="cpp1-number">0</span><span class="cpp1-symbol">] =  a[</span><span class="cpp1-number">1</span><span class="cpp1-symbol">]*b[</span><span class="cpp1-number">2</span><span class="cpp1-symbol">] - a[</span><span class="cpp1-number">2</span><span class="cpp1-symbol">]*b[</span><span class="cpp1-number">1</span><span class="cpp1-symbol">];
     c[</span><span class="cpp1-number">1</span><span class="cpp1-symbol">] =  a[</span><span class="cpp1-number">2</span><span class="cpp1-symbol">]*b[</span><span class="cpp1-number">0</span><span class="cpp1-symbol">] - a[</span><span class="cpp1-number">0</span><span class="cpp1-symbol">]*b[</span><span class="cpp1-number">2</span><span class="cpp1-symbol">];
     c[</span><span class="cpp1-number">2</span><span class="cpp1-symbol">] =  a[</span><span class="cpp1-number">0</span><span class="cpp1-symbol">]*b[</span><span class="cpp1-number">1</span><span class="cpp1-symbol">] - a[</span><span class="cpp1-number">1</span><span class="cpp1-symbol">]*b[</span><span class="cpp1-number">0</span><span class="cpp1-symbol">];
}

</span><span class="cpp1-reservedword">void</span><span class="cpp1-space"> cross_product_atoms(</span><span class="cpp1-reservedword">float</span><span class="cpp1-space"> *c,ATOMS *A,</span><span class="cpp1-reservedword">int</span><span class="cpp1-space"> a0,</span><span class="cpp1-reservedword">int</span><span class="cpp1-space"> a1, </span><span class="cpp1-reservedword">int</span><span class="cpp1-space"> b0,</span><span class="cpp1-reservedword">int</span><span class="cpp1-space"> b1){
     </span><span class="cpp1-reservedword">int</span><span class="cpp1-space"> k;
     </span><span class="cpp1-reservedword">float</span><span class="cpp1-space"> a[</span><span class="cpp1-number">3</span><span class="cpp1-symbol">],b[</span><span class="cpp1-number">3</span><span class="cpp1-symbol">];
     </span><span class="cpp1-reservedword">for</span><span class="cpp1-symbol">(k=</span><span class="cpp1-number">0</span><span class="cpp1-symbol">;k&lt;</span><span class="cpp1-number">3</span><span class="cpp1-symbol">;k++){
          a[k]=A[a1].r[k]-A[a0].r[k];            
          b[k]=A[b1].r[k]-A[b0].r[k];            
     }
     cross_product(c,a,b);
}
</span><span class="cpp1-reservedword">float</span><span class="cpp1-space"> dot_product(</span><span class="cpp1-reservedword">float</span><span class="cpp1-space"> *a,</span><span class="cpp1-reservedword">float</span><span class="cpp1-space"> *b){
      </span><span class="cpp1-reservedword">return</span><span class="cpp1-space"> a[</span><span class="cpp1-number">0</span><span class="cpp1-symbol">]*b[</span><span class="cpp1-number">0</span><span class="cpp1-symbol">]+a[</span><span class="cpp1-number">1</span><span class="cpp1-symbol">]*b[</span><span class="cpp1-number">1</span><span class="cpp1-symbol">]+a[</span><span class="cpp1-number">2</span><span class="cpp1-symbol">]*b[</span><span class="cpp1-number">2</span><span class="cpp1-symbol">];
}

</span><span class="cpp1-reservedword">void</span><span class="cpp1-space"> normalize_vector(</span><span class="cpp1-reservedword">float</span><span class="cpp1-space"> *x){
     </span><span class="cpp1-reservedword">float</span><span class="cpp1-space"> d;
     </span><span class="cpp1-reservedword">int</span><span class="cpp1-space"> i;
     d = sqrt(dot_product(x,x));
     </span><span class="cpp1-reservedword">for</span><span class="cpp1-symbol">(i=</span><span class="cpp1-number">0</span><span class="cpp1-symbol">;i&lt;</span><span class="cpp1-number">3</span><span class="cpp1-symbol">;i++) x[i]/=d;
}

</span><span class="cpp1-reservedword">void</span><span class="cpp1-space"> display_model(</span><span class="cpp1-reservedword">int</span><span class="cpp1-space"> nA,</span><span class="cpp1-reservedword">int</span><span class="cpp1-space"> nB,ATOMS *A,BONDS *B, </span><span class="cpp1-reservedword">float</span><span class="cpp1-space"> scale){
     </span><span class="cpp1-reservedword">int</span><span class="cpp1-space"> i,j,k,bf,b1[</span><span class="cpp1-number">4</span><span class="cpp1-symbol">],b2[</span><span class="cpp1-number">4</span><span class="cpp1-symbol">];
     </span><span class="cpp1-reservedword">float</span><span class="cpp1-space"> r[</span><span class="cpp1-number">3</span><span class="cpp1-symbol">],d,ut[</span><span class="cpp1-number">4</span><span class="cpp1-symbol">][</span><span class="cpp1-number">3</span><span class="cpp1-symbol">],u[</span><span class="cpp1-number">3</span><span class="cpp1-symbol">],l[</span><span class="cpp1-number">3</span><span class="cpp1-symbol">];
     </span><span class="cpp1-reservedword">for</span><span class="cpp1-symbol">(i=</span><span class="cpp1-number">0</span><span class="cpp1-symbol">;i&lt;nA;i++){
           glPushMatrix();
           glTranslatef(A[i].r[</span><span class="cpp1-number">0</span><span class="cpp1-symbol">],A[i].r[</span><span class="cpp1-number">1</span><span class="cpp1-symbol">],A[i].r[</span><span class="cpp1-number">2</span><span class="cpp1-symbol">]);
           printf(</span><span class="cpp1-string">&quot;Atom %d %f %f %f\n&quot;</span><span class="cpp1-symbol">,A[i].Z,A[i].r[</span><span class="cpp1-number">0</span><span class="cpp1-symbol">],A[i].r[</span><span class="cpp1-number">1</span><span class="cpp1-symbol">],A[i].r[</span><span class="cpp1-number">2</span><span class="cpp1-symbol">]);
           glColor3f(color_table[A[i].Z][</span><span class="cpp1-number">0</span><span class="cpp1-symbol">],color_table[A[i].Z][</span><span class="cpp1-number">1</span><span class="cpp1-symbol">],color_table[A[i].Z][</span><span class="cpp1-number">2</span><span class="cpp1-symbol">]);
           printf(</span><span class="cpp1-string">&quot;Color %f %f %f\n&quot;</span><span class="cpp1-symbol">,color_table[A[i].Z][</span><span class="cpp1-number">0</span><span class="cpp1-symbol">],color_table[A[i].Z][</span><span class="cpp1-number">1</span><span class="cpp1-symbol">],color_table[A[i].Z][</span><span class="cpp1-number">2</span><span class="cpp1-symbol">]);
           glutSolidSphere(KONSTANTA*</span><span class="cpp1-number">3</span><span class="cpp1-symbol">,</span><span class="cpp1-number">20</span><span class="cpp1-symbol">,</span><span class="cpp1-number">20</span><span class="cpp1-symbol">);
           glPopMatrix();            
     }
     glColor3f(</span><span class="cpp1-float">0.5</span><span class="cpp1-symbol">,</span><span class="cpp1-float">.5</span><span class="cpp1-symbol">,</span><span class="cpp1-float">.5</span><span class="cpp1-symbol">);
     </span><span class="cpp1-reservedword">for</span><span class="cpp1-symbol">(i=</span><span class="cpp1-number">0</span><span class="cpp1-symbol">;i&lt;nB;i++){
           glPushMatrix();
           glTranslatef(A[B[i].X].r[</span><span class="cpp1-number">0</span><span class="cpp1-symbol">],A[B[i].X].r[</span><span class="cpp1-number">1</span><span class="cpp1-symbol">],A[B[i].X].r[</span><span class="cpp1-number">2</span><span class="cpp1-symbol">]);
           </span><span class="cpp1-reservedword">for</span><span class="cpp1-symbol">(j=</span><span class="cpp1-number">0</span><span class="cpp1-symbol">;j&lt;</span><span class="cpp1-number">3</span><span class="cpp1-symbol">;j++) r[j]=A[B[i].Y].r[j]-A[B[i].X].r[j];
           d = sqrt(dot_product(r,r));
           </span><span class="cpp1-reservedword">switch</span><span class="cpp1-symbol">(B[i].type){
                </span><span class="cpp1-reservedword">default</span><span class="cpp1-symbol">:             
                </span><span class="cpp1-reservedword">case</span><span class="cpp1-space"> </span><span class="cpp1-number">1</span><span class="cpp1-symbol">:
                   glRotatef(</span><span class="cpp1-number">180</span><span class="cpp1-symbol">,r[</span><span class="cpp1-number">0</span><span class="cpp1-symbol">],r[</span><span class="cpp1-number">1</span><span class="cpp1-symbol">],r[</span><span class="cpp1-number">2</span><span class="cpp1-symbol">]+d);
                   glutSolidCylinder(KONSTANTA,d,</span><span class="cpp1-number">20</span><span class="cpp1-symbol">,</span><span class="cpp1-number">20</span><span class="cpp1-symbol">);
                   </span><span class="cpp1-reservedword">break</span><span class="cpp1-symbol">;
                </span><span class="cpp1-reservedword">case</span><span class="cpp1-space"> </span><span class="cpp1-number">3</span><span class="cpp1-symbol">:
                   glRotatef(</span><span class="cpp1-number">180</span><span class="cpp1-symbol">,r[</span><span class="cpp1-number">0</span><span class="cpp1-symbol">],r[</span><span class="cpp1-number">1</span><span class="cpp1-symbol">],r[</span><span class="cpp1-number">2</span><span class="cpp1-symbol">]+d);
                   glTranslatef(RADIUS*KONSTANTA,</span><span class="cpp1-number">0</span><span class="cpp1-symbol">,</span><span class="cpp1-number">0</span><span class="cpp1-symbol">);
                   glutSolidCylinder(KONSTANTA,d,</span><span class="cpp1-number">20</span><span class="cpp1-symbol">,</span><span class="cpp1-number">20</span><span class="cpp1-symbol">);
                   glTranslatef(-RADIUS*(</span><span class="cpp1-float">1.5</span><span class="cpp1-symbol">)*KONSTANTA,RADIUS*</span><span class="cpp1-float">0.866025404</span><span class="cpp1-symbol">*KONSTANTA,</span><span class="cpp1-number">0</span><span class="cpp1-symbol">);
                   glutSolidCylinder(KONSTANTA,d,</span><span class="cpp1-number">20</span><span class="cpp1-symbol">,</span><span class="cpp1-number">20</span><span class="cpp1-symbol">);
                   glTranslatef(</span><span class="cpp1-number">0</span><span class="cpp1-symbol">,-</span><span class="cpp1-number">2</span><span class="cpp1-symbol">*RADIUS*</span><span class="cpp1-float">0.866025404</span><span class="cpp1-symbol">*KONSTANTA,</span><span class="cpp1-number">0</span><span class="cpp1-symbol">);
                   glutSolidCylinder(KONSTANTA,d,</span><span class="cpp1-number">20</span><span class="cpp1-symbol">,</span><span class="cpp1-number">20</span><span class="cpp1-symbol">);                   
                   </span><span class="cpp1-reservedword">break</span><span class="cpp1-symbol">;                    
               </span><span class="cpp1-reservedword">case</span><span class="cpp1-space"> </span><span class="cpp1-number">2</span><span class="cpp1-symbol">:
                    printf(</span><span class="cpp1-string">&quot;Bond %d\n&quot;</span><span class="cpp1-symbol">,i);
                    </span><span class="cpp1-reservedword">for</span><span class="cpp1-symbol">(j=bf=</span><span class="cpp1-number">0</span><span class="cpp1-symbol">;j&lt;nB;j++)</span><span class="cpp1-reservedword">if</span><span class="cpp1-symbol">(i!=j){
                         </span><span class="cpp1-reservedword">if</span><span class="cpp1-space"> (B[i].X==B[j].X){
                            b1[bf]=B[i].X;
                            b2[bf++]=B[j].Y;
                            printf(</span><span class="cpp1-string">&quot;bf%d(%d-%d)\n&quot;</span><span class="cpp1-symbol">,bf,b1[bf-</span><span class="cpp1-number">1</span><span class="cpp1-symbol">],b2[bf-</span><span class="cpp1-number">1</span><span class="cpp1-symbol">]);
                         }
                         </span><span class="cpp1-reservedword">if</span><span class="cpp1-space"> (B[i].X==B[j].Y){
                            b1[bf]=B[i].X;
                            b2[bf++]=B[j].X;
                            printf(</span><span class="cpp1-string">&quot;bf%d(%d-%d)\n&quot;</span><span class="cpp1-symbol">,bf,b1[bf-</span><span class="cpp1-number">1</span><span class="cpp1-symbol">],b2[bf-</span><span class="cpp1-number">1</span><span class="cpp1-symbol">]);
                         }
                         </span><span class="cpp1-reservedword">if</span><span class="cpp1-space"> (B[i].Y==B[j].X){
                            b1[bf]=B[i].Y;
                            b2[bf++]=B[j].Y;
                            printf(</span><span class="cpp1-string">&quot;bf%d(%d-%d)\n&quot;</span><span class="cpp1-symbol">,bf,b1[bf-</span><span class="cpp1-number">1</span><span class="cpp1-symbol">],b2[bf-</span><span class="cpp1-number">1</span><span class="cpp1-symbol">]);
                         }
                         </span><span class="cpp1-reservedword">if</span><span class="cpp1-space"> (B[i].Y==B[j].Y){
                            b1[bf]=B[i].Y;
                            b2[bf++]=B[j].X;
                            printf(</span><span class="cpp1-string">&quot;bf%d(%d-%d)\n&quot;</span><span class="cpp1-symbol">,bf,b1[bf-</span><span class="cpp1-number">1</span><span class="cpp1-symbol">],b2[bf-</span><span class="cpp1-number">1</span><span class="cpp1-symbol">]);
                         }
                    }
                    </span><span class="cpp1-reservedword">for</span><span class="cpp1-symbol">(j=</span><span class="cpp1-number">0</span><span class="cpp1-symbol">;j&lt;bf;j++){
                       cross_product_atoms(ut[j],A,B[i].X,B[i].Y,b1[j],b2[j]);
                       normalize_vector(ut[j]);               
                    }
                    </span><span class="cpp1-reservedword">if</span><span class="cpp1-space"> (bf) </span><span class="cpp1-reservedword">for</span><span class="cpp1-symbol">(k=</span><span class="cpp1-number">0</span><span class="cpp1-symbol">;k&lt;</span><span class="cpp1-number">3</span><span class="cpp1-symbol">;k++) u[k]=ut[</span><span class="cpp1-number">0</span><span class="cpp1-symbol">][k];
                    </span><span class="cpp1-reservedword">for</span><span class="cpp1-symbol">(j=</span><span class="cpp1-number">1</span><span class="cpp1-symbol">;j&lt;bf;j++){
                         </span><span class="cpp1-reservedword">if</span><span class="cpp1-space"> (dot_product(u,ut[j])&gt;</span><span class="cpp1-number">0</span><span class="cpp1-symbol">){
                              </span><span class="cpp1-reservedword">for</span><span class="cpp1-symbol">(k=</span><span class="cpp1-number">0</span><span class="cpp1-symbol">;k&lt;</span><span class="cpp1-number">3</span><span class="cpp1-symbol">;k++) u[k]+=ut[j][k];
                         }</span><span class="cpp1-reservedword">else</span><span class="cpp1-symbol">{
                              </span><span class="cpp1-reservedword">for</span><span class="cpp1-symbol">(k=</span><span class="cpp1-number">0</span><span class="cpp1-symbol">;k&lt;</span><span class="cpp1-number">3</span><span class="cpp1-symbol">;k++) u[k]-=ut[j][k];
                         }                              
                    }
                    </span><span class="cpp1-reservedword">if</span><span class="cpp1-symbol">(bf){
                         cross_product(l,u,r);
                         normalize_vector(l);
                         glPushMatrix();
                         glTranslatef(RADIUS*KONSTANTA*l[</span><span class="cpp1-number">0</span><span class="cpp1-symbol">],RADIUS*KONSTANTA*l[</span><span class="cpp1-number">1</span><span class="cpp1-symbol">],RADIUS*KONSTANTA*l[</span><span class="cpp1-number">2</span><span class="cpp1-symbol">]);
                         glRotatef(</span><span class="cpp1-number">180</span><span class="cpp1-symbol">,r[</span><span class="cpp1-number">0</span><span class="cpp1-symbol">],r[</span><span class="cpp1-number">1</span><span class="cpp1-symbol">],r[</span><span class="cpp1-number">2</span><span class="cpp1-symbol">]+d);
                         glutSolidCylinder(KONSTANTA,d,</span><span class="cpp1-number">20</span><span class="cpp1-symbol">,</span><span class="cpp1-number">20</span><span class="cpp1-symbol">);
                         glPopMatrix();  
                         glPushMatrix();
                         glTranslatef(-RADIUS*KONSTANTA*l[</span><span class="cpp1-number">0</span><span class="cpp1-symbol">],-RADIUS*KONSTANTA*l[</span><span class="cpp1-number">1</span><span class="cpp1-symbol">],-RADIUS*KONSTANTA*l[</span><span class="cpp1-number">2</span><span class="cpp1-symbol">]);
                         glRotatef(</span><span class="cpp1-number">180</span><span class="cpp1-symbol">,r[</span><span class="cpp1-number">0</span><span class="cpp1-symbol">],r[</span><span class="cpp1-number">1</span><span class="cpp1-symbol">],r[</span><span class="cpp1-number">2</span><span class="cpp1-symbol">]+d);
                         glutSolidCylinder(KONSTANTA,d,</span><span class="cpp1-number">20</span><span class="cpp1-symbol">,</span><span class="cpp1-number">20</span><span class="cpp1-symbol">);
                         glPopMatrix();  
                    } </span><span class="cpp1-reservedword">else</span><span class="cpp1-space"> {
                         glPushMatrix();
                         glTranslatef(RADIUS*KONSTANTA,</span><span class="cpp1-number">0</span><span class="cpp1-symbol">,</span><span class="cpp1-number">0</span><span class="cpp1-symbol">);
                         glRotatef(</span><span class="cpp1-number">180</span><span class="cpp1-symbol">,r[</span><span class="cpp1-number">0</span><span class="cpp1-symbol">],r[</span><span class="cpp1-number">1</span><span class="cpp1-symbol">],r[</span><span class="cpp1-number">2</span><span class="cpp1-symbol">]+d);
                         glutSolidCylinder(KONSTANTA,d,</span><span class="cpp1-number">20</span><span class="cpp1-symbol">,</span><span class="cpp1-number">20</span><span class="cpp1-symbol">);
                         glPopMatrix();  
                         glPushMatrix();
                         glTranslatef(-RADIUS*KONSTANTA,</span><span class="cpp1-number">0</span><span class="cpp1-symbol">,</span><span class="cpp1-number">0</span><span class="cpp1-symbol">);
                         glRotatef(</span><span class="cpp1-number">180</span><span class="cpp1-symbol">,r[</span><span class="cpp1-number">0</span><span class="cpp1-symbol">],r[</span><span class="cpp1-number">1</span><span class="cpp1-symbol">],r[</span><span class="cpp1-number">2</span><span class="cpp1-symbol">]+d);
                         glutSolidCylinder(KONSTANTA,d,</span><span class="cpp1-number">20</span><span class="cpp1-symbol">,</span><span class="cpp1-number">20</span><span class="cpp1-symbol">);
                         glPopMatrix();    
                    }
                   </span><span class="cpp1-reservedword">break</span><span class="cpp1-symbol">;     
           }
           glPopMatrix();            
     }

}

</span><span class="cpp1-reservedword">void</span><span class="cpp1-space"> take_a_picture(</span><span class="cpp1-reservedword">void</span><span class="cpp1-symbol">){
     </span><span class="cpp1-reservedword">unsigned</span><span class="cpp1-space"> </span><span class="cpp1-reservedword">char</span><span class="cpp1-space"> *data;
     FILE *f=fopen(</span><span class="cpp1-string">&quot;obrazek.bmp&quot;</span><span class="cpp1-symbol">,</span><span class="cpp1-string">&quot;wb&quot;</span><span class="cpp1-symbol">);
     </span><span class="cpp1-reservedword">char</span><span class="cpp1-space"> header[</span><span class="cpp1-number">54</span><span class="cpp1-symbol">]={     
          </span><span class="cpp1-number">66</span><span class="cpp1-symbol">, </span><span class="cpp1-number">77</span><span class="cpp1-symbol">, </span><span class="cpp1-number">54</span><span class="cpp1-symbol">, -</span><span class="cpp1-number">32</span><span class="cpp1-symbol">, </span><span class="cpp1-number">46</span><span class="cpp1-symbol">, </span><span class="cpp1-number">0</span><span class="cpp1-symbol">, </span><span class="cpp1-number">0</span><span class="cpp1-symbol">, </span><span class="cpp1-number">0</span><span class="cpp1-symbol">, 
          </span><span class="cpp1-number">0</span><span class="cpp1-symbol">, </span><span class="cpp1-number">0</span><span class="cpp1-symbol">, </span><span class="cpp1-number">54</span><span class="cpp1-symbol">, </span><span class="cpp1-number">0</span><span class="cpp1-symbol">, </span><span class="cpp1-number">0</span><span class="cpp1-symbol">, </span><span class="cpp1-number">0</span><span class="cpp1-symbol">, </span><span class="cpp1-number">40</span><span class="cpp1-symbol">, </span><span class="cpp1-number">0</span><span class="cpp1-symbol">,
          </span><span class="cpp1-number">0</span><span class="cpp1-symbol">, </span><span class="cpp1-number">0</span><span class="cpp1-symbol">, </span><span class="cpp1-number">0</span><span class="cpp1-symbol">, </span><span class="cpp1-number">5</span><span class="cpp1-symbol">, </span><span class="cpp1-number">0</span><span class="cpp1-symbol">, </span><span class="cpp1-number">0</span><span class="cpp1-symbol">, </span><span class="cpp1-number">32</span><span class="cpp1-symbol">, </span><span class="cpp1-number">3</span><span class="cpp1-symbol">,
          </span><span class="cpp1-number">0</span><span class="cpp1-symbol">, </span><span class="cpp1-number">0</span><span class="cpp1-symbol">, </span><span class="cpp1-number">1</span><span class="cpp1-symbol">, </span><span class="cpp1-number">0</span><span class="cpp1-symbol">, </span><span class="cpp1-number">24</span><span class="cpp1-symbol">, </span><span class="cpp1-number">0</span><span class="cpp1-symbol">, </span><span class="cpp1-number">0</span><span class="cpp1-symbol">, </span><span class="cpp1-number">0</span><span class="cpp1-symbol">, </span><span class="cpp1-number">0</span><span class="cpp1-symbol">, </span><span class="cpp1-number">0</span><span class="cpp1-symbol">, </span><span class="cpp1-number">0</span><span class="cpp1-symbol">, -</span><span class="cpp1-number">32</span><span class="cpp1-symbol">, </span><span class="cpp1-number">46</span><span class="cpp1-symbol">, </span><span class="cpp1-number">0</span><span class="cpp1-symbol">, </span><span class="cpp1-number">0</span><span class="cpp1-symbol">, </span><span class="cpp1-number">0</span><span class="cpp1-symbol">, </span><span class="cpp1-number">0</span><span class="cpp1-symbol">, </span><span class="cpp1-number">0</span><span class="cpp1-symbol">, </span><span class="cpp1-number">0</span><span class="cpp1-symbol">, </span><span class="cpp1-number">0</span><span class="cpp1-symbol">, </span><span class="cpp1-number">0</span><span class="cpp1-symbol">, </span><span class="cpp1-number">0</span><span class="cpp1-symbol">, </span><span class="cpp1-number">0</span><span class="cpp1-symbol">, </span><span class="cpp1-number">0</span><span class="cpp1-symbol">, </span><span class="cpp1-number">0</span><span class="cpp1-symbol">,
          </span><span class="cpp1-number">0</span><span class="cpp1-symbol">, </span><span class="cpp1-number">0</span><span class="cpp1-symbol">, </span><span class="cpp1-number">0</span><span class="cpp1-symbol">, </span><span class="cpp1-number">0</span><span class="cpp1-symbol">, </span><span class="cpp1-number">0
</span><span class="cpp1-space">     };     
     </span><span class="cpp1-reservedword">int</span><span class="cpp1-space"> w,h,*i;    
     w = glutGet(GLUT_WINDOW_WIDTH);
     h = glutGet(GLUT_WINDOW_HEIGHT);
</span><span class="cpp1-comment">/*
     i = (void *)(&amp;header[17]);
     *i = w;
     i = (void *)(&amp;header[21]);
     *i = h;
*/
</span><span class="cpp1-space">     data = (</span><span class="cpp1-reservedword">unsigned</span><span class="cpp1-space"> </span><span class="cpp1-reservedword">char</span><span class="cpp1-space"> *)malloc(w*h*</span><span class="cpp1-number">3</span><span class="cpp1-symbol">);
     glReadBuffer(GL_BACK); 
     glPixelZoom(</span><span class="cpp1-float">1.0f</span><span class="cpp1-symbol">,</span><span class="cpp1-float">1.0f</span><span class="cpp1-symbol">);
     glReadPixels(</span><span class="cpp1-number">0</span><span class="cpp1-symbol">,</span><span class="cpp1-number">0</span><span class="cpp1-symbol">,w,h,GL_RGB,GL_UNSIGNED_BYTE, data); 
     fwrite(header,</span><span class="cpp1-number">1</span><span class="cpp1-symbol">,</span><span class="cpp1-reservedword">sizeof</span><span class="cpp1-symbol">(header),f);
     fwrite(data,</span><span class="cpp1-number">1</span><span class="cpp1-symbol">,w*h*</span><span class="cpp1-number">3</span><span class="cpp1-symbol">,f);
     fclose(f);
}


</span><span class="cpp1-comment">/* data */
</span><span class="cpp1-reservedword">int</span><span class="cpp1-space"> nA,nB;
ATOMS *A;
BONDS *B;
</span><span class="cpp1-reservedword">float</span><span class="cpp1-space"> scale;

</span><span class="cpp1-reservedword">void</span><span class="cpp1-space"> resize(</span><span class="cpp1-reservedword">int</span><span class="cpp1-space"> width, </span><span class="cpp1-reservedword">int</span><span class="cpp1-space"> height)
{
    </span><span class="cpp1-reservedword">const</span><span class="cpp1-space"> </span><span class="cpp1-reservedword">float</span><span class="cpp1-space"> ar = (</span><span class="cpp1-reservedword">float</span><span class="cpp1-symbol">) width / (</span><span class="cpp1-reservedword">float</span><span class="cpp1-symbol">) height;
    glViewport(</span><span class="cpp1-number">0</span><span class="cpp1-symbol">, </span><span class="cpp1-number">0</span><span class="cpp1-symbol">, width, height);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    </span><span class="cpp1-reservedword">if</span><span class="cpp1-symbol">( ar &gt; </span><span class="cpp1-number">1</span><span class="cpp1-space"> )
        glFrustum( -ar, ar, -</span><span class="cpp1-float">1.0</span><span class="cpp1-symbol">, </span><span class="cpp1-float">1.0</span><span class="cpp1-symbol">, </span><span class="cpp1-float">2.0</span><span class="cpp1-symbol">, </span><span class="cpp1-float">100.0</span><span class="cpp1-space"> );
    </span><span class="cpp1-reservedword">else
</span><span class="cpp1-space">        glFrustum( -</span><span class="cpp1-float">1.0</span><span class="cpp1-symbol">, </span><span class="cpp1-float">1.0</span><span class="cpp1-symbol">, -</span><span class="cpp1-number">1</span><span class="cpp1-symbol">/ar, </span><span class="cpp1-number">1</span><span class="cpp1-symbol">/ar, </span><span class="cpp1-float">2.0</span><span class="cpp1-symbol">, </span><span class="cpp1-float">100.0</span><span class="cpp1-space"> );
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity() ;
}

</span><span class="cpp1-reservedword">int</span><span class="cpp1-space"> list;
</span><span class="cpp1-reservedword">void</span><span class="cpp1-space"> display(</span><span class="cpp1-reservedword">void</span><span class="cpp1-symbol">)
{
    </span><span class="cpp1-reservedword">const</span><span class="cpp1-space"> </span><span class="cpp1-reservedword">double</span><span class="cpp1-space"> t = glutGet(GLUT_ELAPSED_TIME) / </span><span class="cpp1-float">1000.0</span><span class="cpp1-symbol">;

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glLoadIdentity();
    glTranslatef(</span><span class="cpp1-number">0</span><span class="cpp1-symbol">,</span><span class="cpp1-number">0</span><span class="cpp1-symbol">,-</span><span class="cpp1-number">6</span><span class="cpp1-symbol">);
    </span><span class="cpp1-reservedword">if</span><span class="cpp1-space"> (!glIsList(list)){
         glNewList(list=glGenLists(</span><span class="cpp1-number">1</span><span class="cpp1-symbol">),GL_COMPILE);
         glScalef(</span><span class="cpp1-number">4</span><span class="cpp1-symbol">/scale,</span><span class="cpp1-number">4</span><span class="cpp1-symbol">/scale,</span><span class="cpp1-number">4</span><span class="cpp1-symbol">/scale);
         display_model(nA,nB,A,B,scale);         
         glEndList();                
    }
</span><span class="cpp1-comment">//    glRotatef(10*t,1,1,1);
</span><span class="cpp1-space">    glCallList(list);
    glutSwapBuffers();
}


</span><span class="cpp1-reservedword">void</span><span class="cpp1-space"> key(</span><span class="cpp1-reservedword">unsigned</span><span class="cpp1-space"> </span><span class="cpp1-reservedword">char</span><span class="cpp1-space"> key, </span><span class="cpp1-reservedword">int</span><span class="cpp1-space"> x, </span><span class="cpp1-reservedword">int</span><span class="cpp1-space"> y)
{
    </span><span class="cpp1-reservedword">switch</span><span class="cpp1-space"> (key){
    </span><span class="cpp1-reservedword">case</span><span class="cpp1-space"> </span><span class="cpp1-number">27</span><span class="cpp1-space"> :
    </span><span class="cpp1-reservedword">case</span><span class="cpp1-space"> 'Q':
    </span><span class="cpp1-reservedword">case</span><span class="cpp1-space"> 'q':
        exit(</span><span class="cpp1-number">0</span><span class="cpp1-symbol">);
        </span><span class="cpp1-reservedword">break</span><span class="cpp1-symbol">;
    </span><span class="cpp1-reservedword">case</span><span class="cpp1-space"> 's':
    </span><span class="cpp1-reservedword">case</span><span class="cpp1-space"> 'S':
         take_a_picture();
         </span><span class="cpp1-reservedword">break</span><span class="cpp1-symbol">;    
    </span><span class="cpp1-reservedword">default</span><span class="cpp1-symbol">:
        </span><span class="cpp1-reservedword">break</span><span class="cpp1-symbol">;
    }
    glutPostRedisplay();
}


</span><span class="cpp1-reservedword">void</span><span class="cpp1-space"> idle(</span><span class="cpp1-reservedword">void</span><span class="cpp1-symbol">){
    glutPostRedisplay();
}

</span><span class="cpp1-reservedword">const</span><span class="cpp1-space"> GLfloat light_ambient[]  = { </span><span class="cpp1-float">0.0f</span><span class="cpp1-symbol">, </span><span class="cpp1-float">0.0f</span><span class="cpp1-symbol">, </span><span class="cpp1-float">0.0f</span><span class="cpp1-symbol">, </span><span class="cpp1-float">1.0f</span><span class="cpp1-space"> };
</span><span class="cpp1-reservedword">const</span><span class="cpp1-space"> GLfloat light_diffuse[]  = { </span><span class="cpp1-float">1.0f</span><span class="cpp1-symbol">, </span><span class="cpp1-float">1.0f</span><span class="cpp1-symbol">, </span><span class="cpp1-float">1.0f</span><span class="cpp1-symbol">, </span><span class="cpp1-float">1.0f</span><span class="cpp1-space"> };
</span><span class="cpp1-reservedword">const</span><span class="cpp1-space"> GLfloat light_specular[] = { </span><span class="cpp1-float">1.0f</span><span class="cpp1-symbol">, </span><span class="cpp1-float">1.0f</span><span class="cpp1-symbol">, </span><span class="cpp1-float">1.0f</span><span class="cpp1-symbol">, </span><span class="cpp1-float">1.0f</span><span class="cpp1-space"> };
</span><span class="cpp1-reservedword">const</span><span class="cpp1-space"> GLfloat light_position[] = { </span><span class="cpp1-float">2.0f</span><span class="cpp1-symbol">, </span><span class="cpp1-float">5.0f</span><span class="cpp1-symbol">, </span><span class="cpp1-float">5.0f</span><span class="cpp1-symbol">, </span><span class="cpp1-float">0.0f</span><span class="cpp1-space"> };

</span><span class="cpp1-reservedword">const</span><span class="cpp1-space"> GLfloat mat_ambient[]    = { </span><span class="cpp1-float">0.7f</span><span class="cpp1-symbol">, </span><span class="cpp1-float">0.7f</span><span class="cpp1-symbol">, </span><span class="cpp1-float">0.7f</span><span class="cpp1-symbol">, </span><span class="cpp1-float">1.0f</span><span class="cpp1-space"> };
</span><span class="cpp1-reservedword">const</span><span class="cpp1-space"> GLfloat mat_diffuse[]    = { </span><span class="cpp1-float">0.8f</span><span class="cpp1-symbol">, </span><span class="cpp1-float">0.8f</span><span class="cpp1-symbol">, </span><span class="cpp1-float">0.8f</span><span class="cpp1-symbol">, </span><span class="cpp1-float">1.0f</span><span class="cpp1-space"> };
</span><span class="cpp1-reservedword">const</span><span class="cpp1-space"> GLfloat mat_specular[]   = { </span><span class="cpp1-float">1.0f</span><span class="cpp1-symbol">, </span><span class="cpp1-float">1.0f</span><span class="cpp1-symbol">, </span><span class="cpp1-float">1.0f</span><span class="cpp1-symbol">, </span><span class="cpp1-float">1.0f</span><span class="cpp1-space"> };
</span><span class="cpp1-reservedword">const</span><span class="cpp1-space"> GLfloat high_shininess[] = { </span><span class="cpp1-float">100.0f</span><span class="cpp1-space"> };

</span><span class="cpp1-reservedword">int</span><span class="cpp1-space"> main(</span><span class="cpp1-reservedword">int</span><span class="cpp1-space"> argc, </span><span class="cpp1-reservedword">char</span><span class="cpp1-space"> **argv)
{
    glutInitWindowSize(</span><span class="cpp1-number">640</span><span class="cpp1-symbol">,</span><span class="cpp1-number">480</span><span class="cpp1-symbol">);
    glutInitWindowPosition(</span><span class="cpp1-number">40</span><span class="cpp1-symbol">,</span><span class="cpp1-number">40</span><span class="cpp1-symbol">);
    glutInit(&amp;argc, argv);
    glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);

    glutCreateWindow(argv[</span><span class="cpp1-number">1</span><span class="cpp1-symbol">]);

    glutReshapeFunc(resize);
    glutDisplayFunc(display);
    glutKeyboardFunc(key);
    glutIdleFunc(idle);

    glClearColor(</span><span class="cpp1-number">1</span><span class="cpp1-symbol">,</span><span class="cpp1-number">1</span><span class="cpp1-symbol">,</span><span class="cpp1-number">1</span><span class="cpp1-symbol">,</span><span class="cpp1-number">1</span><span class="cpp1-symbol">);

    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_LESS);

    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);
    glEnable(GL_NORMALIZE);
    glEnable(GL_COLOR_MATERIAL);

    glLightfv(GL_LIGHT0, GL_AMBIENT,  light_ambient);
    glLightfv(GL_LIGHT0, GL_DIFFUSE,  light_diffuse);
    glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
    glLightfv(GL_LIGHT0, GL_POSITION, light_position);

    glMaterialfv(GL_FRONT, GL_AMBIENT,   mat_ambient);
    glMaterialfv(GL_FRONT, GL_DIFFUSE,   mat_diffuse);
    glMaterialfv(GL_FRONT, GL_SPECULAR,  mat_specular);
    glMaterialfv(GL_FRONT, GL_SHININESS, high_shininess);

    glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST);
    glEnable (GL_POLYGON_SMOOTH);
    glHint(GL_POLYGON_SMOOTH_HINT,GL_NICEST);
    

glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

glHint(GL_POINT_SMOOTH, GL_NICEST);
glHint(GL_LINE_SMOOTH, GL_NICEST);
glHint(GL_POLYGON_SMOOTH, GL_NICEST);

glEnable(GL_POINT_SMOOTH);
glEnable(GL_LINE_SMOOTH);
glEnable(GL_POLYGON_SMOOTH);


    load_color_table();
    load_molfile(argv[</span><span class="cpp1-number">1</span><span class="cpp1-symbol">],&amp;nA,&amp;nB,&amp;A,&amp;B,&amp;scale);
    glutFullScreen();
    glutMainLoop();
    </span><span class="cpp1-reservedword">return</span><span class="cpp1-space"> EXIT_SUCCESS;
}

</span></span>
</code></pre>
</body>
</html>